﻿<link href="/UI/css/components/login.min.css" rel="stylesheet" />
<!--<script src="/Scripts/Liber.Crypter.min.js"></script>-->
<template>
    <div id="loginPanel">
        <h5 id="loginTitle">登录</h5>
        <br />
        <div id="loginForm">
            <div class="InputGroup">
                <input id="loginKey" placeholder="手机号/邮箱" v-model="key" v-on:keydown.enter.stop="inputKeyEnd" v-on:blur="validateKey" />
                <small class="errtip">{{keyerr||'&nbsp'}}</small>
            </div>
            <div class="InputGroup">
                <input id="loginPwd" placeholder="请输入密码" type="password" v-model="pwd" v-on:keydown.enter.stop="loginHandler"/>
                <small class="errtip">{{pwderr||'&nbsp'}}</small>
            </div>
            <div class="InputGroup">
                <button id="btnLogin" class="onfocus" @click="loginHandler" v-bind:disabled="key.length==0" style="width:100%">登   录</button>
            </div>
            <div class="InputGroup" id="lnkPanel">
                <a href="/My/RetrivePwd.html" id="goPwdBack">忘记密码？</a>
                <a href="/Acnt/Register.html" id="goRegist">免费注册</a>
            </div>
        </div>
    </div>
</template>
<script>
    opt = {
        mounted: function () {
            $.Cookie("ssologout", "ok", { expires: -1 });
            var ln = $.Cookie("LastAcnt");
            if (ln) {
                this.key = ln;
                $("#loginPwd").focus();
            }
            else {
                $("#loginKey").focus();
            };
        },
        data: function () {
            return {
                User: null,
                key: '',
                pwd: '',
                mode:'normal',
                keyerr: '',
                pwderr: ''
            };
        },
        methods: {
            inputKeyEnd: function () {
                if (this.$data.key) {
                    $("#loginPwd").focus();
                }
            },
            validateKey: function (ev) {
                if (!this.$data.key) {
                    this.$data.keyerr = '请输入帐号';
                }
                else {
                    this.$data.keyerr = '';
                }
            },
            loginHandler: function () {
                $("#btnLogin").disable().vl("正在登录...");
                
                var key = this.key;
                var ur = {
                    key: this.key,
                    pwd:this.pwd.toString().md4()
                };
                let vm = this;
                $.post("/api/FlashQ/Login", ur, function (rtn) {
                    if (rtn.IsPositive) {
                        $.Cookie("LastAcnt", key, { expires: 10 * 24 * 60 });
                        vm.$emit("onloginend");
                    }
                    else {
                        $("#btnLogin").enable().vl("登录");
                        vm.keyerr = errFormate(rtn);
                    }
                });
            }
        }
    }
</script>
